﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Globalization;

namespace JavaSubstitutes
{
	public static class ColorExtensions
	{
		//Typical usage:
		//ColorExtensions.decode("#a07070")
		public static Color decode(string sRGBHex)
		{
			//chop off the "#" and continue
			return FromHexAdobe(sRGBHex.Substring(1, sRGBHex.Length-1));
		}

		public static SolidColorBrush ToBrush(this Color color)
		{
			return new SolidColorBrush(color);
		}

		///Expects strings in the adobe format: "00CFFF", alpha will be max
		//extensions can only make instance methods, so this'll be static on the extension obj
		//itself rather than maknig a helper class in addition to the extension
		public static Color FromHexAdobe(string rgbHex)
		{
			return Color.FromArgb(0xff,
				byte.Parse(rgbHex.Substring(0, 2), NumberStyles.HexNumber), //00
				byte.Parse(rgbHex.Substring(2, 2), NumberStyles.HexNumber), //CF
				byte.Parse(rgbHex.Substring(4, 2), NumberStyles.HexNumber));//FF
		}
	}
}
